package com.example.demo.drools.base;

/**
 * 执行规则结果
 */
public class CheckResult {

	/**
	 * 结果描述
	 */
	private String message;
	/**
	 * 结果编码
	 */
	private String code;
	
	/**
	 * 返回数据
	 */
	private Object data;
	
	/**
	 * 成功码
	 */
	private static final String SUCCESS_CODE = "200";
	
	/**
	 * 失败码
	 */
	private static final String FAIL_CODE = "400";
	
	
	public CheckResult() {

	}
	
	/**
	 * 转换为result对象
	 * @return
	 */
	public Result<Object> transf(){
		 Result<Object> result = new  Result<>();
		 result.setCode(this.code);
		 result.setMessage(this.message); 
		 result.setData(this.data);
		return result;
	}
	
	/**
	 * 失败
	 * @param code
	 * @param message
	 * @return
	 */
	public static  CheckResult fail(String code, String message) {
		CheckResult result = new CheckResult();
		result.setCode(code);
		result.setMessage(message);
		return result;
	}
	
	/**
	 * 失败, code为400
	 * @param message
	 * @return
	 */
	public static  CheckResult fail(String message) {
		return fail(FAIL_CODE, message);
	}
	
	/**
	 * 失败, code为400, message为匹配不成功
	 * @return
	 */
	public static  CheckResult fail() {
		return fail("匹配不成功");
	}
	
	
	/**
	 * 匹配是否成功
	 * @return
	 */
	public boolean isSuccess() {
		return SUCCESS_CODE.equals(code);
	}

	
	
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}


	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "CheckResult [message=" + message + ", code=" + code + ", data=" + data + "]";
	}

}
